/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package serverP;


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.InetAddress;
import java.net.UnknownHostException;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

/**
 *
 * @author Sandro
 */
public class MenuServer {

        private JFrame jf;
        private JLabel ip;
        private JComboBox map;
        private JLabel gameName;
        private JLabel gameStatus;
        private JTextField newGame;
        private JButton startGame;
        private JButton stopServer;

       
    public MenuServer(final Server s){
        super();
        jf=new JFrame("Server Vidas");
        jf.setBounds(100,100,420,200);
       
        jf.getContentPane().setLayout(null);

        newGame = new JTextField();
        newGame.setBounds(50,10,100,20);
        jf.getContentPane().add(newGame);
        newGame.setText("Juego");// Nombre de juego por defecto

        map=new JComboBox();
        map.setBounds(170, 10, 100, 20);
        jf.getContentPane().add(map);
        map.addItem("Matriz");
        map.addItem("Grande");
        map.addItem("Tunnig");

        ip = new JLabel();
        ip.setBounds(50,40,150,20);
        jf.getContentPane().add(ip);

        gameName = new JLabel();
        gameName.setBounds(50,70,150,20);
        jf.getContentPane().add(gameName);
        gameName.setText("Juego:  No Hay Juego");

        gameStatus = new JLabel();
        gameStatus.setBounds(50,100,300,20);
        jf.getContentPane().add(gameStatus);
        gameStatus.setText("Estado:  No Informado");

        startGame=new JButton("Iniciar");
        startGame.setBounds(50,130,100,20);
        jf.getContentPane().add(startGame);

     
        stopServer=new JButton("Salir");
        stopServer.setBounds(270,130,100,20);
        jf.getContentPane().add(stopServer);

        try {
            InetAddress addr = InetAddress.getLocalHost();
           this.setIp(addr.getHostAddress());
        } catch (UnknownHostException ex) {
             System.out.println("Unknown Host Exception");
        }

         /*Varias Clases anónimas para conectar a la interface gráfica*/
        /*Este clase anónima se invoca cuando se presiona salir el juego*/
        stopServer.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                System.exit(0);}});

       /*Esta clase anónima se invoca cuando se presiona apagar el server*/
        startGame.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                startGame.setEnabled(false);
                s.startGame();
                }});

        jf.setVisible(true);
    }

    
      public String getGameName(){
       return this.newGame.getText();
      }

      public String getGameMap(){
       return (String) this.map.getSelectedItem();
      }

      public void setIp(String ip) {
            this.ip.setText("IP:  " + ip);
        }

      public void setSatus(String s){
        this.gameStatus.setText("Estado:  "+s);
      }

      public void setGameName(String name) {
        this.gameName.setText("Juego:  "+name);
      }

      public void setStartGameEnabled(boolean t){
        startGame.setEnabled(t);
      }

    
      
}
